package com.fdl.dao.model.security;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.fdl.dao.base.Dao;
import com.fdl.dao.security.RoleDao;

/**
 * 角色 
 * @project: hb-intra
 * @Date:2010-8-6
 * @version  1.0
 * @Company: 33e9
 * @author zhangYong.huang
 */
public class Role implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static RoleDao roleDao;

	private Long id;
	
	private String name;

	private String descn;

	private Set permissions = new HashSet(0);

	private String authorize;

	// Constructors

	/**
	 * default constructor
	 */
	public Role() {}

	/**
	 * minimal constructor
	 */
	public Role(String name) {
		this.name = name;
	}

	/**
	 * full constructor
	 */
//	public Role(String name, String descn, Set permissions) {
//		this.name = name;
//		this.descn = descn;
//		this.permissions = permissions;
//	}

	protected Dao getDao() {
		return roleDao;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescn() {
		return this.descn;
	}

	public void setDescn(String descn) {
		this.descn = descn;
	}
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Set getPermissions() {
		return this.permissions;
	}

	public void setPermissions(Set permissions) {
		this.permissions = permissions;
	}

	public String getAuthorize() {
		return authorize;
	}

	public void setAuthorize(String authorize) {
		this.authorize = authorize;
	}

	public static List getAll() {
		return roleDao.getAll();
	}

	public static Role load(Serializable id) {
		return roleDao.get(id);
	}

	public static void setRoleDao(RoleDao roleDao) {
		Role.roleDao = roleDao;
	}

	public boolean hasPermission(String auth) {
		Iterator it = permissions.iterator();
		while (it.hasNext()) {
			Permission permission = (Permission) it.next();
			if (permission.getName().equals(auth))
				return true;
		}

		return false;
	}
}
